<?php
namespace  Wap\Controller;
use Wap\Controller\CommonController;

class UserController extends CommonController {
	//array(验证字段,验证规则,错误提示,[验证条件,附加规则,验证时间])
  public $seKey     = 'ThinkPHP.CN';
	 /**
      +----------------------------------------------------------
     * 首页
     *
      +----------------------------------------------------------
     */
    public function register() {


    header("Content-Type:text/html; charset=utf-8");
     if(IS_POST){
     	 $data = I('post.');
    
            if($_SESSION['codedd']!=$_POST['yanzhengma']){
  $this->error('短信验证码错误',U('User/register'));

          }
    if(!check_verify(I('verify_code'))){
           $this->error('验证码错误',U('User/register'));
        
          } 
 

       $arr  = array();
       $arr["phone"]=$data["phone"];
     $arr["pass"]=md5($data["password"]);
      $arr["user"]=$data["user"];
        $result1=M("user")->where(array('phone'=>$arr["phone"]))->find();

        if ($result1) {
             $this->error("对不起!该手机号已被注册");
        }else{

    $result=M("user")->add($arr);
      if($result){
         session('codedd',null); 
       $this->redirect(U('User/login'));

      }else {
        $this->error("对不起！注册失败");
      }

        }
       
  

     }else{
   
	    $this->display('register');
     }


    }


		/**
	 		+----------------------------------------------------------
	 	 * login
	 	 *
	 		+----------------------------------------------------------
	 	 */
	 public function login() {

	 header("Content-Type:text/html; charset=utf-8");
	 if(IS_POST){
       $arr  = array();
       
       $arr["phone"]=I('post.phone');
       $arr["pass"]=md5(I('post.password'));
       $map["phone"] = array("eq",$arr["phone"]);
       $map["pass"] = array("eq",$arr["pass"]);

       try{
        $result=M("user")->where($map)->find();
         if ($result) {
           $_SESSION["phone"]=$result["phone"];
            $_SESSION["userid"]=$result["id"];
            $_SESSION["userr"]=$result["user"];
            $_SESSION["zhuangtai"]=$result["status"];
            $_SESSION['zt'] =$result["zt"];
          $this->redirect(U('Index/index'));
         }else{
           $this->error("登录失败,用户名密码错误");
         }
       }catch(Exception $e){
          $this->error("登录失败,".$e->getMessage());
       }
       
	 }else{
	 	$this->display('login');
	 }

   }

   public function loginout(){
   	     session("userr",null);
         session("zhuangtai",null);
         session("phone",null);
         session("userid",null);
         session("zt",null);
         session("goods",null);
   	 $this->redirect(U('Index/index'));
   }


    public function modifyPassword(){
      header("Content-Type:text/html; charset=utf-8");
      $result=M("user")->where("phone='".$_SESSION['phone']."'")->find();
      if($result["pass"]!=md5(I("post.oldpassword"))){
        echo 1;
      }else{
        $result["pass"]=md5(I("post.newpassword"));
        if(M("user")->where("phone='".$_SESSION['phone']."'")->save($result)){
          echo 2;
        }else{
          echo 0;
        }
      }
    }



public function mima(){

$this->display();

}



		
   
   
    public function upload(){
     $upload = new \Think\Upload();// 实例化上传类
     $upload->maxSize   =     3145728 ;// 设置附件上传大小
     $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
     $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
     $upload->savePath  =     ''; // 设置附件上传（子）目录
     // 上传文件
     $info   =   $upload->upload();
     $price=I("post.price");
    if(!$info) {// 上传错误提示错误信息
        $this->error($upload->getError());
    }else{// 上传成功
      $phone=$_SESSION["phone"];
      $result["pic"]=$info["photo"]["savepath"].$info["photo"]["savename"];
      $result["phone"]=$phone;
      $result["name"]=M("user")->where("phone='".$phone."'")->getField("name");
      $result["time"]=date("Y-m-d",time());
      $result["serial"]=date("YmdHis",time()).randCode(8,1);
      $result["total_fee"]=$price;
      if(M("chongzhi")->add($result)){
        $this->success("上传成功");
      }
    }
}



 public function sheji(){

   
    $data=M('zlist')->select();
  $this->data=$data;


$this->display();

 }

 public function shenhe(){

    if (IS_POST) {
 

         $arr['chengshi']=I('post.chengshi');
         $arr['area']=I('post.area');
        $arr['fengge']=I('post.fengge');
          $arr['baojia']=I('post.baojia');
          $arr['touxiang']=I('post.touxiang');
          $arr['linian']=I('post.linian');
          $arr['title']=I('post.title');
          $arr['content']=  implode(",",$_POST['content']);
          $_SESSION['zt'] = 1;
          $arr['zt']=$_SESSION['zt'];
          $arr['img']=  implode(",",$_POST['photos']);
    if (M('user')->where(array('id'=>$_SESSION['userid']))->save($arr)) {
             $this->redirect(U('User/shenhe'));
    }
       }





  $this->display();
 }



   public function gouwu(){
  
     foreach ($_SESSION['goods'] as &$value) {
        $jj=M('user')->where('id='.$value['userid'])->find();
        $value['user']=$jj['user'];

     }


$this->assign('gouwu',$_SESSION['goods']);
$this->display();

   }

   public function gw(){
  
         $id=I('post.id');
         foreach ($_SESSION['goods'] as $key => $value) {
              if ($key==$id) {
               echo 2;
             exit();
              }
         }
         $m=M('shangpin')->find($id);
         
       
    if($_SESSION['goods'][$id]=$m){
          echo 1;
}
   } 


   public function del(){
 
         $id=I('post.id');
         unset($_SESSION['goods'][$id]);
         echo 1;


   }
   public function delete(){

    unset($_SESSION['goods']);
echo 1;

   }

   public function dingdan(){
             $fid=I('get.fid');
             if (is_numeric($fid)) {
               $count = M('dingdan')->where('sjid="'.$_SESSION["userid"].'" and fid="'.$fid.'" and jdzt=1')->count();

$Page = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    //$Page->rollPage=4;
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();// 分页显示输



            $data=M('dingdan')->alias('a')->field('a.*, b.user,b.chengshi,b.baojia')->join('zyb_user b on b.id=a.sjid')->order('id desc')->where('a.sjid="'.$_SESSION["userid"].'" and fid="'.$fid.'" and jdzt=1')->limit($Page->firstRow.','.$Page->listRows)->select();
            // echo M('dingdan')->_sql();
      
              foreach ($data as &$value) {
                            $shangpin=M('shangpin')->where('id='.$value['gid'])->select();
                            $value['dingdan']=$shangpin;
             
                            } 


             }else{


$count = M('dingdan')->where('sjid="'.$_SESSION["userid"].'" and jdzt=1')->count();
              $Page = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    //$Page->rollPage=4;
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();// 分页显示输


            $data=M('dingdan')->alias('a')->field('a.*, b.user,b.chengshi,b.baojia')->join('zyb_user b on b.id=a.sjid')->order('id desc')->where('a.sjid="'.$_SESSION["userid"].'" and jdzt=1')->limit($Page->firstRow.','.$Page->listRows)->select();
            // echo M('dingdan')->_sql();
      
              foreach ($data as &$value) {
                            $shangpin=M('shangpin')->where('id='.$value['gid'])->select();
                            $value['dingdan']=$shangpin;
             
                            } 
                            }             
$this->assign('page',$show);
$this->assign('data',$data);

    $this->display();
   }

  public function yuyue(){

       $id=I('get.id');
       if (is_numeric($id)){

$count = M('yuyue')->where('status="'.$id.'" and uid="'.$_SESSION["userid"].'" ')->count();
              $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    //$Page->rollPage=4;
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();// 分页显示输



        
            $data=M('yuyue')->where('status="'.$id.'" and uid="'.$_SESSION["userid"].'" ')->limit($Page->firstRow.','.$Page->listRows)->select();

        }else{
        $count = M('yuyue')->where('uid='.$_SESSION["userid"])->count();
              $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    //$Page->rollPage=4;
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();// 分页显示输



      $data=M('yuyue')->where('uid='.$_SESSION["userid"])->limit($Page->firstRow.','.$Page->listRows)->select();

    }
   $this->assign('page',$show);
     $this->assign('data',$data);
    $this->display();

   }

  public function daijiedan(){
            $id=I('post.id');
            $data = array('fid'=>'8','zid'=>'3','htid'=>'4');
             $m=M('dingdan')->where('id='.$id)->setField($data);
              echo 1;


 }
   public function daijiedan1(){
            $id=I('post.id');
            $data = array('fid'=>'6','zid'=>'12','htid'=>'2');
             $m=M('dingdan')->where('id='.$id)->setField($data);
              echo 1;


 }
   




   public function shangchuan(){
 

if (IS_POST) {
    $id=I('post.id');
 $data['biaoti']=I('post.biaoti');
   $data['intro']=htmlspecialchars_decode(I('post.intro'));
   $data['zid']=5;
   $data['fid']=3;
     $data['htid']=8;
   $m=M('dingdan')->where('id='.$id)->setField($data);
}

    $this->display();

 }

  public function fangan(){

  $id=I('get.id');
  $m=M('dingdan')->where('id='.$id)->find();

  $this->assign('fangan',$m);

    $this->display();
}
  public function fangansj(){

  $id=I('get.id');
  $m=M('dingdan')->where('id='.$id)->find();

  $this->assign('fangan',$m);

    $this->display();
}

     public function shoucang1(){
      $id=I('post.shangpin');
      $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
      if($result){
        if(empty($result['shangpin'])){
            $result['shangpin'] = $id.",";
        }else{
          $shangpin = explode(',',$result['shangpin']);
          $is_has = false;
          foreach ($shangpin as $key => $value) {
            if($value==$id){
              unset($shangpin[$key]);
              $is_has = true;
              break;
            }
          }
          $result['shangpin'] = implode(',',$shangpin);
          if(!$is_has){
            $result["shangpin"]=$result["shangpin"].$id.",";
          }
        }
        
        M('shoucang')->save($result);
      }else{
        $data = array("userid"=>$_SESSION["userid"],"shangpin"=>$id.",");
        M('shoucang')->add($data);
      }

 echo 1;

    
   }


public function sheji1(){
      $id=I('post.sheji');
      
      $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
      if($result){
        if(empty($result['sheji'])){
            $result['sheji'] = $id.",";
        }else{
          $sheji = explode(',',$result['sheji']);
          $is_has = false;
          foreach ($sheji as $key => $value) {
            if($value==$id){
              unset($sheji[$key]);
              $is_has = true;
              break;
            }
          }
          $result['sheji'] = implode(',',$sheji);
          if(!$is_has){
            $result["sheji"]=$result["sheji"].$id.",";
          }
        }
        
        M('shoucang')->save($result);
      }else{
        $data = array("userid"=>$_SESSION["userid"],"sheji"=>$id.",");
        M('shoucang')->add($data);
      }

 echo 1;

    
   }

 public function sheji2(){
  $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
        if($result){
          $sheji_shoucang = explode(',',$result['sheji']);
       
        
          $where['id'] = array('in',$sheji_shoucang);
          $count=M('user')->where($where)->count();
       $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    //$Page->rollPage=4;
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();// 分页显示输


          $data = M('user')->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();

    }

        foreach ($data as &$value) {
                  $ggg=M('shangpin')->where('userid='.$value['id'])->count();
                 $price=M('shangpin')->where('userid='.$value['id'])->find();
                  $value['count']=$ggg;
                  $value['price']=$price['price'];
              }

    $this->assign("page",$show);
    $this->assign("data",$data);
 
    $this->display();
    
   }
   public function shoucang(){
  
    // $data = array();
    $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
        if($result){
          $shangpin_shoucang = explode(',',$result['shangpin']);
       
     
          $where['a.id'] = array('in',$shangpin_shoucang);

     $count=M('shangpin')->alias('a')->field('a.name,a.id,a.img, a.fengge,a.huxing,b.user as username')->join('zyb_user b on b.id = a.userid')->where($where)->count();

 $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    //$Page->rollPage=4;
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();// 分页显示输


          $data = M('shangpin')->alias('a')->field('a.name,a.id,a.img, a.fengge,a.huxing,b.user as username')->join('zyb_user b on b.id = a.userid')->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();
          foreach ($data as $key => &$value) {
             if(strlen($value['name'])>30){
            $value['name']=mb_substr($value['name'],0,30,'utf-8').'...';
   
}
                  
          }

        }

       $this->assign("page",$show);
    $this->assign("data",$data);

    $this->display();
    
   }


   public function shoucangdel(){
   $id=I('get.id');
      $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
      if($result){
        if(empty($result['shangpin'])){
            $result['shangpin'] = $id.",";
        }else{
          $shangpin = explode(',',$result['shangpin']);
          $is_has = false;
          foreach ($shangpin as $key => $value) {
            if($value==$id){
              unset($shangpin[$key]);
              $is_has = true;
              break;
            }
          }
          $result['shangpin'] = implode(',',$shangpin);
          if(!$is_has){
            $result["shangpin"]=$result["shangpin"].$id.",";
          }
        }
        
        M('shoucang')->save($result);
      }
     $this->redirect('User/shoucang');

   }

   public function shejidel(){
   $id=I('get.id');
      $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
      if($result){
        if(empty($result['sheji'])){
            $result['sheji'] = $id.",";
        }else{
          $sheji = explode(',',$result['sheji']);
          $is_has = false;
          foreach ($sheji as $key => $value) {
            if($value==$id){
              unset($sheji[$key]);
              $is_has = true;
              break;
            }
          }
          $result['sheji'] = implode(',',$sheji);
          if(!$is_has){
            $result["sheji"]=$result["sheji"].$id.",";
          }
        }
        
        M('shoucang')->save($result);
      }
     $this->redirect('User/sheji2');

   }



   public function quanzidel(){
   $id=I('get.id');
      $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
      if($result){
        if(empty($result['quanzi'])){
            $result['quanzi'] = $id.",";
        }else{
          $quanzi = explode(',',$result['quanzi']);
          $is_has = false;
          foreach ($quanzi as $key => $value) {
            if($value==$id){
              unset($quanzi[$key]);
              $is_has = true;
              break;
            }
          }
          $result['quanzi'] = implode(',',$quanzi);
          if(!$is_has){
            $result["quanzi"]=$result["quanzi"].$id.",";
          }
        }
        
        M('shoucang')->save($result);
      }
     $this->redirect('User/quanzi');

   }



public function anli(){

     $count=M('shangpin')->where('userid='.$_SESSION['userid'])->count();
$Page = new \Think\Page($count,12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();


          $anli=M('shangpin')->where('userid='.$_SESSION['userid'])->limit($Page->firstRow.','.$Page->listRows)->select();
              $this->assign('page',$show);
        $this->assign('data',$anli);

         $this->display();
}


public function addAdmin() {
  
    $lis=M('zlist');
    $list=$lis->select();
    $ljj=M('huxing')->select();
    $this->assign('ljj',$ljj);
    $this->assign('list',$list);
    if (IS_POST) {
      $data=array();
      $data=I('post.');

        
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     553145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{// 上传成功
                    $data["img"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                  
                }



            $data['userid']=$_SESSION['userid'];
      $data['intro']=htmlspecialchars_decode(I('post.intro'));

      if(M('shangpin')->add($data)){
        $this->redirect(U('User/anli'));
      }else{
        $this->error('添加失败');
      }
    } else {
    
      $this->display();
    }
  }
  






public function dizhi(){
if (IS_POST) {
    $data['diqu']=I('post.sheng').I('post.shi').I('post.qu');
    $data['address']=I('post.address');
    $data['name']=I('post.xingming');
     $data['tel']=I('post.tel');
      $data['status']=I('post.status');
      $data['dzid']=$_SESSION['userid'];
       if (empty($data['status'])) {
            
      if (M('address')->add($data)) {
        $this->redirect(U('User/dizhi'));
      }

       }else{
      $m=M('address')->where(array('dzid'=>$_SESSION['userid'],'status'=>1))->find();
       if($m){
        M('address')->where(array('id'=>$m['id']))->setField('status',0);
        M('address')->add($data);
        $this->redirect(U('User/dizhi'));

       } else{
         M('address')->add($data);
         $this->redirect(U('User/dizhi'));
       } 


     }
  
}

            $id=I('get.id');
           
      if (is_numeric($id)) {
        $dizhi=M('address')->where('id='.$id)->delete();
          $this->redirect(U('User/dizhi'));
      }
           $dizhi=M('address')->order('id desc')->where('dzid='.$_SESSION['userid'])->select();
           $this->data=$dizhi;
     $this->display();
}

public function dizhitj(){

if (IS_POST) {  
    $data['diqu']=I('post.sheng').I('post.shi').I('post.qu');
    $data['address']=I('post.address');
    $data['name']=I('post.xingming');
     $data['tel']=I('post.tel');
      $data['status']=I('post.status');
      $data['dzid']=$_SESSION['userid'];
      M('address')->add($data);

}

   $this->display();
}

public function dzupdate(){

    $id=I('get.id');
   if (is_numeric($id)) {
        $dizhi=M('address')->where('id='.$id)->find();
        $this->data=$dizhi;
      }

     if (IS_POST) { 
      $idd=I('post.id');
       $data['diqu']=I('post.sheng').I('post.shi').I('post.qu');
    $data['address']=I('post.address');
    $data['name']=I('post.xingming');
     $data['tel']=I('post.tel');
      $data['status']=I('post.status');
           if (empty($data['status'])) {
                    $dizhi=M('address')->where('id='.$idd)->save($data);
        $this->redirect(U('User/dizhi'));
           }else{
            $m=M('address')->where(array('dzid'=>$_SESSION['userid'],'status'=>1))->find();
              if ($m) {
                      M('address')->where(array('id'=>$m['id']))->setField('status',0);
                      $dizhi=M('address')->where('id='.$idd)->save($data);
                       $this->redirect(U('User/dizhi'));  
              }else{
                $dizhi=M('address')->where('id='.$idd)->save($data);
                       $this->redirect(U('User/dizhi'));
              }

           }


      } 




$this->display();
}



public function fankui1(){

  $data['fankui']=I('post.fankui');
                 $data['userid']=$_SESSION['userid'];
           if(M('fankui')->add($data)){

               echo 1;

           }else{
            echo 0;
           }

}


public function fankui(){
        
  $this->display();
}


public function ziliao(){
 if (IS_POST) {
        
          $arr['user']=I('post.user');
          $arr['phone']=I('post.tel');
          $arr['chengshi']=I('post.chengshi');
          $arr['area']=I('post.area');
          $arr['fengge']=I('post.fengge');
          $arr['baojia']=I('post.baojia');
           $arr['touxiang']=I('post.touxiang');
          if (empty($arr['touxiang'])) {
            unset($arr['touxiang']);
             if (M('user')->where('id='.$_SESSION['userid'])->save($arr)) {
             $this->redirect(U('user/ziliao'));
          }
          }else{
          if (M('user')->where('id='.$_SESSION['userid'])->save($arr)) {
           $this->redirect(U('user/ziliao'));
          }
}
         

 }



     $zz=M('user')->where('id='.$_SESSION['userid'])->find();

   $li=M('zlist');
    $data=$li->select();
           $this->assign('data',$data);
             $this->assign('zz',$zz);
  $this->display();
}



public function ziliao1(){

 if (IS_POST) {
        
          $arr['user']=I('post.user');
          $arr['phone']=I('post.tel');
          $arr['chengshi']=I('post.chengshi');
    
           $arr['touxiang']=I('post.touxiang');
          if (empty($arr['touxiang'])) {
            unset($arr['touxiang']);
             if (M('user')->where('id='.$_SESSION['userid'])->save($arr)) {
             $this->redirect(U('user/ziliao1'));
          }
          }else{
          if (M('user')->where('id='.$_SESSION['userid'])->save($arr)) {
           $this->redirect(U('user/ziliao1'));
          }
}
         

 }



     $zz=M('user')->where('id='.$_SESSION['userid'])->find();

       $this->assign('zz',$zz);



  $this->display();
}

public function xuqiu(){

       if (IS_POST) {
           $data=I('post.');

      if(M('user')->where('id='.$_SESSION['userid'])->setField($data)){
        $this->redirect(U('User/xuqiu'));
      }


       }



    $li=M('zlist');
    $lis=$li->select();
    $hux=M('huxing')->select();
    $use=M('user')->where('id='.$_SESSION['userid'])->find();
    $this->assign('use',$use);
    $this->assign('hux',$hux);
    $this->assign('lis',$lis);
    $this->display();
}


    
    public function tupian(){


       


 if (!empty($_FILES)) {

            //图片上传设置
             $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     553145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
       
            $images = $upload->upload();
    
            //判断是否有图
            if($images){
                $info=$images['Filedata']['savepath'].$images['Filedata']['savename'];
  


                //返回文件地址和名给JS作回调用
                echo $info;
         
                 
            }
            else{
                $this->error($upload->getError());//获取失败信息
            }
        }else{

        }







    }
























public function person(){

           
            $id=I('get.id');
           $zid=I('get.zid');

      if (is_numeric($id)) {
        $dizhi=M('dingdan')->where('id='.$id)->delete();
          $this->redirect(U('User/person'));
      }
if (is_numeric($zid)) {


 $count = M('dingdan')->where('uid="'.$_SESSION['userid'].'" and zid="'.$zid.'"')->count();// 查询满足要求的总记录数
   
$Page = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();


    $data=M('dingdan')->order('id desc')->where('uid="'.$_SESSION['userid'].'" and zid="'.$zid.'"')->limit($Page->firstRow.','.$Page->listRows)->select();
     foreach ($data as  &$value) {
               $good=M('shangpin')->alias('a')->field('a.*,b.user,b.baojia,b.chengshi')->join('zyb_user b on b.id=a.userid')->where('a.id='.$value['gid'])->select();
           $value['dingdan']=$good;

     }
} else{


 $count = M('dingdan')->where('uid='.$_SESSION['userid'])->count();// 查询满足要求的总记录数
   
    $Page = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    //$Page->rollPage=4;
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();// 分页显示输



     $data=M('dingdan')->order('id desc')->where('uid='.$_SESSION['userid'])->limit($Page->firstRow.','.$Page->listRows)->select();
     foreach ($data as  &$value) {
               $good=M('shangpin')->alias('a')->field('a.*,b.user,b.baojia,b.chengshi')->join('zyb_user b on b.id=a.userid')->where('a.id='.$value['gid'])->select();
           $value['dingdan']=$good;

     }
}
 $this->assign('page',$show);
   $this->assign('data',$data);
  $this->display();

}





























    public function verify_code() {
    $Verify = new \Think\Verify();  
    $Verify->fontSize = 18;  
    $Verify->length   = 4;  
    $Verify->useNoise = false;  
    $Verify->codeSet = '0123456789';  
    $Verify->imageW = 130;  
    $Verify->imageH = 50;  
    //$Verify->expire = 600;  
    $Verify->entry();  
    }

/* 加密验证码 */


    /*
     *  我的发布圈子
     *  @author xiejg
     *  date:2017.3.28
     */
    public function release(){
        $uid =$_SESSION['userid'];
    $count= M('Quanzi')->where(array('uid'=>$uid))->count();
$Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      
      
        $show = $Page->show();


        $list = M('Quanzi')->where(array('uid'=>$uid))->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('count',$count);
 foreach ($list as $key => &$value) {
               $value['img1']  =explode(',',$value['img']); 
               if(strlen($value['title'])>15){
            $value['title']=mb_substr($value['title'],0,15,'utf-8').'...';
   
}
               if(strlen($value['content'])>15){
            $value['content']=mb_substr($value['content'],0,15,'utf-8').'...';
   
}

 }

        $this->assign('page',$show);
        $this->assign('list',$list);
        $this->display();
    }
    public function release1(){
         $id=I('post.id');
        M('quanzi')->where(array('id'=>$id))->delete();
          M('comments')->where(array('qz_id'=>$id))->delete();
        echo 1;

    }

    /*
     *  我的信息
     *  @author xiejg
     *  date：2017.3.28
     */
    public  function message(){
        $id =$_SESSION['userid'];
        if (isset($id)){

          $num = M('Comments')->where(array('to_uid'=>$id,'status'=>1))->count();  //查询未读的消息
          $Page = new \Think\Page($num,12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      
      
        $show = $Page->show();


            $info = M('Comments')->where(array('to_uid'=>$id,'status'=>1))->limit($Page->firstRow.','.$Page->listRows)->select();
            foreach ($info as $k => $v){
                $info[$k]['u_title'] = M('Quanzi')->where(array('id'=>$info[$k]['qz_id']))->getField('title');
            }
           
            $this->assign('num',$num);
             $this->assign('page',$show);
            $this->assign('info',$info);
        }
        $this->display();
    }

public function butai(){
          $id=I('post.id');
          $data=array('fid'=>4,'zid'=>6);
          $m=M('dingdan')->where('id='.$id)->setField($data);

  echo 1;


}

public function queding(){
          $id=I('post.id');
          $data=array('fid'=>5,'zid'=>7,'htid'=>9);
          $m=M('dingdan')->where('id='.$id)->setField($data);

 echo 1;


}

public function pingjia(){
if (IS_POST) {
     $data['gid']=I('post.gid');

   $data['intro']=htmlspecialchars_decode(I('post.intro'));
   $data['uid']=$_SESSION['userid'];
   $data['time']=time();
   $m=M('pinglun')->add($data);

  $id=I('post.id');

 $data1['zid']=11;
    $data1['htid']=17;
   $jj=M('dingdan')->where('id='.$id)->setField($data1);


}



   $this->display();
}


public function quanzi(){


$result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();

        if($result){
          $quanzi_shoucang = explode(',',$result['quanzi']);
       
        
          $where['id'] = array('in',$quanzi_shoucang);


                        $count=M('quanzi')->where($where)->count();

          $Page = new \Think\Page($count,6);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      
      
        $show = $Page->show();

          $data = M('quanzi')->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();

    }
              foreach ($data as  &$value) {
                  $value['img']=explode(',',$value['img']);
              }
  
    $this->assign("page",$show);
    $this->assign("data",$data);
 

   


  $this->display();
}

public function quanzi1(){
    $id=I('post.quanzi');
 
      $result = M('shoucang')->where(array("userid"=>$_SESSION["userid"]))->find();
      if($result){
        if(empty($result['quanzi'])){
            $result['quanzi'] = $id.",";
        }else{
          $quanzi = explode(',',$result['quanzi']);
          $is_has = false;
          foreach ($quanzi as $key => $value) {
            if($value==$id){
              unset($quanzi[$key]);
              $is_has = true;
              break;
            }
          }
          $result['quanzi'] = implode(',',$quanzi);
          if(!$is_has){
            $result["quanzi"]=$result["quanzi"].$id.",";
          }
        }
        
        M('shoucang')->save($result);
      }else{
        $data = array("userid"=>$_SESSION["userid"],"quanzi"=>$id.",");
        M('shoucang')->add($data);
      }

 echo 1;



}



public function wangji(){

if (IS_POST) {
  
  
            if($_SESSION['xiugai']!=$_POST['yanzhengma']){
  $this->error('短信验证码错误');

          }
  
    $wangji=M('user')->where(array('phone'=>$_POST['phone']))->setField('pass',md5($_POST['password']));
if ($wangji) {
  session('xiugai',null);
  $this->redirect(U('User/login'));
}
  

}

  $this->display();
}


public function anlidl(){
   $id=I('post.id');

   $m=M('shangpin')->where('id='.$id)->delete();
   echo 1;

}



  public function search(){

          $list=M('zlist')->select();
          
          $huxing=M('huxing')->order('id asc')->select();
          
          $fengge = I("get.fengge");
       $huxing1 = I("get.huxing");
       $where = "";

       if(!empty($fengge)){
          $data = M('zlist')->where("id = $fengge")->find();
          if(empty($where)){
            $where .= "a.fengge = '".$data['type_name']."'";
          }else{
            $where .= " and a.fengge = '".$data['type_name']."'";
          }
          
           
       }

       if(!empty($huxing1)){
          $data1 = M('huxing')->where("id=$huxing1")->find();
          if(empty($where)){
            $where .= "a.huxing = '".$data1['huxing']."'";
          }else{
            $where .= " and a.huxing = '".$data1['huxing']."'";
          }
       }
       
       $title=I('post.title');
    $map['a.name'] =array('like',"%$title%");
          $map['a.fengge'] =array('like',"%$title%");
          $map['a.huxing'] =array('like',"%$title%");
          $map['_logic'] = 'or';
    $shangpin=M('shangpin')->alias("a")->field("a.id,a.name,a.fengge,a.huxing,a.area,a.price,a.intro,a.img,a.userid,b.user as username")->join("zyb_user b on b.id = a.userid")->where($map)->order("a.id desc")->select();
         
            $this->assign("fengge",$fengge);
      $this->assign('list',$list);
      $this->assign('huxing',$huxing);
      $this->assign('huxing1',$huxing1);
            $this->assign('shangpin',$shangpin);
            $this->display();
        
    } 


public function quxiao(){
$id=I('post.id');
          $data=array('fid'=>7,'zid'=>13,'htid'=>15);
          $m=M('dingdan')->where('id='.$id)->setField($data);

  echo 1;



}

public function ddxq(){
  $id=I('get.id');
  $m=M('dingdan')->where('id='.$id)->find();
  $dizhi=M('address')->where('id='.$m['aid'])->find();

  $goods=M('shangpin')->alias('a')->field('a.id,a.name, a.userid,a.fengge,a.huxing,a.area,a.price,a.img,b.user,b.baojia,b.chengshi')->join('zyb_user b on b.id=a.userid')->where('a.id='.$m['gid'])->find();
$this->assign('goods',$goods);
 $this->assign('bianhao',$m);
 $this->assign('dizhi',$dizhi);
  $this->display();
}


public function _empty(){
       
        $this->redirect(U('Index/index'));
    }

}

?>
